package com.shangdiao.sd_server;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.shangdiao.sd_server.constant.Constant;
import com.shangdiao.sd_server.constant.ErrorCode;
import com.shangdiao.sd_server.pojo.ResponseMsg;
import com.shangdiao.sd_server.service.DicService;
import com.shangdiao.sd_server.service.PersonService;
import com.shangdiao.sd_server.service.RedisService;
import com.shangdiao.sd_server.util.RequestUtil;

@Controller
@RequestMapping("/upload")
public class TestController {
	
	@Autowired
	DicService dicService;
	@Autowired
	PersonService personService;
	@Autowired
	RedisService redisService;
	
	@RequestMapping(value = { "/test.json" })
	@ResponseBody
	public Object checktel(HttpServletRequest request, HttpServletResponse response) {
		ResponseMsg retMsg = null;
		String upload_file_name = RequestUtil.get(request, "file_name_aaa");
		System.out.println("upload_file_name>>>" + upload_file_name);
		try {  
			String fromFile = Constant.TEMP_FILE_PATH + upload_file_name;
			String toFile = Constant.LOGO_FILE_PATH + upload_file_name;
            InputStream is = new FileInputStream(fromFile);// 创建文件输入流  
            FileOutputStream fos = new FileOutputStream(toFile);// 文件输出流  
            byte[] buffer = new byte[1024];// 字节数组  
            while (is.read(buffer) != -1) {// 将文件内容写到文件中  
                fos.write(buffer);  
            }  
            is.close();// 输入流关闭  
            fos.close();// 输出流关闭  
        } catch (FileNotFoundException e) {// 捕获文件不存在异常  
            e.printStackTrace();  
        } catch (IOException e) {// 捕获异常  
            e.printStackTrace();  
        }  
		retMsg = new ResponseMsg("成功！", ErrorCode.OK, null);
		return retMsg;
	}
		public static void main(String[] args) {
		
	}
	
}
